package com.city.repository.pub;

import com.city.domain.party.PartyBranch;
import com.city.domain.pub.PubArticle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @deprecation: 公共文章
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-18 13:14
 */
public interface PubArticleRepository extends JpaRepository<PubArticle,Integer> {
    //通过类别查询前面十条数据
    @Query(value = "select * from pub_article where type_name=?1 order by update_time desc limit 0,10", nativeQuery = true)
    List<PubArticle> findPubArticlesByPre(String typeName);


    @Query(value = "select * from pub_article where type_name=?1", nativeQuery = true)
    List<PubArticle> findPubArticlesByType(String typeName);


    PubArticle findPubArticleById(int id);

    //分页查询
    @Query(value = "select * from pub_article limit ?1,?2",nativeQuery = true)
    List<PubArticle> findPubArticleLimit(Integer page, Integer limit);

    //根据文章类别查询
    @Query(value = "select * from pub_article  where type_name = ?1  limit ?2,?3",nativeQuery = true)
    List<PubArticle> findByTypeName(String typeName, Integer page, Integer limit);

    //根据文章来源查询
    @Query(value = "select * from pub_article  where the_source = ?1  limit ?2,?3",nativeQuery = true)
    List<PubArticle> findByTheSource(String theSource, Integer page, Integer limit);

    //根据文章 来源 和类别查询
    @Query(value = "select * from pub_article where type_name = ?1 and the_source=?2 limit ?3,?4",nativeQuery = true)
    List<PubArticle> findByTypeNameAndTheSource(String typeName,String theSource, Integer page, Integer limit);

    //根据文章类别统计记录数
    @Query(value = "SELECT count(*) from pub_article where type_name = ?1",nativeQuery = true)
    long countTypeName(String typeName);

    //根据来源统计记录数
    @Query(value = "select count(*) from pub_article where the_source = ?1",nativeQuery = true)
    long countTheSource(String theSource);

    //根据文章类别 和来源统计
    @Query(value = "select count(*) from pub_article where type_name = ?1 and the_source = ?2",nativeQuery = true)
    long countTypeNameAndTheSource(String typeName,String theSource);



}
